import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Display here.
 * 
 * @author Christian Pérez Zavalija
 * @version 25-Jun-2013
 */
public class Display extends Device
{
    private GreenfootImage imgDisplay;
    
    /**
     * Load the images in an array and displays the Display and called to the constructor of the super class.
     */
    public Display()
    {
        super(10,12,81);
        imgDisplay=new GreenfootImage("Display.png");
        setImage(imgDisplay);
    }
    
    /**
     *  The image is scale in 50%
     */
    public void scale()
    {
        imgDisplay.scale(imgDisplay.getWidth()-40,imgDisplay.getHeight()-50);
    }
    
    /**
     * if you touch one of the pins with the dump, the pins are removed.
     */
    public void eliminate()
    {
        removeTouching(Pin.class);
    }
    
    /**
     * Call the method act () of its super class, Check if the 2 pins are connected to unnamed negative and
     * a pin with this positive letter on the light. If the 2 pins are connected not turn unnamed light.
     */
    public void act() 
    {
        super.act();
        if(pins[2].charge==0&&pins[7].charge==0){
            Light light=new Light();
            if(pins[8].charge==1){
                light.turn(90);
                getWorld().addObject(light,getX()-1,getY()-33);
            }
            else
                getWorld().removeObject(light);
            
        }
        if(pins[2].charge==0&&pins[7].charge==0){
            Light light=new Light();
            if(pins[9].charge==1){
                getWorld().addObject(light,getX()+18,getY()-17);
            }
            else
                getWorld().removeObject(light);
        }
        if(pins[2].charge==0&&pins[7].charge==0){
            Light light=new Light();
            if(pins[3].charge==1){
                getWorld().addObject(light,getX()+18,getY()+17);
            }
            else
                getWorld().removeObject(light);
        }
        if(pins[2].charge==0&&pins[7].charge==0){
            Light light=new Light();
            if(pins[1].charge==1){
                light.turn(90);
                getWorld().addObject(light,getX()-1,getY()+32);
            }
            else
                getWorld().removeObject(light);
            }
        if(pins[2].charge==0&&pins[7].charge==0){
            Light light=new Light();
            if(pins[0].charge==1){
                getWorld().addObject(light,getX()-18,getY()+17);
            }
            else
                getWorld().removeObject(light);
            }
        if(pins[2].charge==0&&pins[7].charge==0){
            Light light=new Light();
            if(pins[6].charge==1){
                getWorld().addObject(light,getX()-17,getY()-17);
            }
            else
                getWorld().removeObject(light);
        }
        if(pins[2].charge==0&&pins[7].charge==0){
            Light light=new Light();
            if(pins[5].charge==1){
                light.turn(90);
                getWorld().addObject(light,getX()-1,getY());
            }
            else
                getWorld().removeObject(light);
        }
    }    
}
